package com.hspedu.newData.LCR;

import com.hspedu.newData.dmsxl.ds.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-17 
 * @Version: 1.0
 */

public class LCR174寻找二叉搜索树中的目标节点 {

    List<Integer> list = new ArrayList<>();
    public int findTargetNode(TreeNode root, int cnt) {
        dfs(root);
        return list.get(list.size() - cnt);
    }

    public void dfs(TreeNode root){
        if (root == null) return;
        dfs(root.left);
        list.add(root.val);
        dfs(root.right);
    }
}
